package entities;

import handlers.Animation;
import handlers.B2dVars;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;

public class B2DSprite {

	protected Body body;
	protected Animation animation;
	protected float width;
	protected float height;

	public B2DSprite(Body body) {
		this.body = body;
		animation = new Animation();
	}

	public void setAnimation(TextureRegion[] reg, float delay) {
		animation.setFrames(reg, delay);
		setWidth(reg[0].getRegionWidth());
		setHeight(reg[0].getRegionHeight());
	}

	public void setAnimation(TextureRegion reg, float delay) {
		setAnimation(new TextureRegion[] { reg }, delay);
	}

	public void update(float dt) {
		animation.update(dt);
	}

	public void render(SpriteBatch sp) {
		sp.begin();
		sp.draw(animation.getFrame(), body.getPosition().x * B2dVars.PPM
				- getWidth() / 2, body.getPosition().y * B2dVars.PPM
				- getHeight() / 2);
		sp.end();
	}

	public Body getBody() {
		return body;
	}

	public float getWidth() {
		return width;
	}

	public void setWidth(float width) {
		this.width = width;
	}

	public float getHeight() {
		return height;
	}

	public void setHeight(float height) {
		this.height = height;
	}

	public Vector2 getPostion() {
		return body.getPosition();
	}

}
